package com.cytech.cloudclinic.moudle.main.setting;

import android.view.View;
import android.widget.TextView;

import com.cytech.cloudclinic.R;
import com.cytech.cloudclinic.base.BaseFragment;
import com.cytech.cloudclinic.dialog.ForgetPasswordDialog;
import com.cytech.cloudclinic.moudle.login.LoginActivity;
import com.cytech.cloudclinic.moudle.main.clinic.admission.prescription.template.PrescriptionTemplateActivity;
import com.cytech.cloudclinic.moudle.main.setting.prescription.PrescriptionModuleActivity;
import com.yechaoa.yutils.SpUtil;

import butterknife.BindView;
import butterknife.OnClick;

import static com.cytech.cloudclinic.app.Constant.USER_TOKEN;

public class SettingFragment extends BaseFragment<SettingPresenter> implements SettingView {
    @BindView(R.id.tv_setting_phone)
    TextView phoneTv;

    ForgetPasswordDialog forgetPasswordDialog;

    public static SettingFragment newInstance() {
        SettingFragment fragment = new SettingFragment();
        //如果有参数，使用Bundle传递
        return fragment;
    }


    @Override
    protected SettingPresenter createPresenter() {
        return new SettingPresenter(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_main_setting;
    }

    @Override
    protected void initView() {
        phoneTv.setText(SpUtil.getString(SpUtil.getString(USER_TOKEN)));
    }

    @Override
    protected void initData() {

    }

    @OnClick(R.id.btn_exit_account)
    public void exitAccount(View view){
        SpUtil.removeByKey(USER_TOKEN);
        LoginActivity.actionStart(getActivity());
        getActivity().finish();
    }

    @OnClick(R.id.btn_setting_update_psw)
    public void updatePassword(View view){
        if(forgetPasswordDialog == null){
            forgetPasswordDialog = new ForgetPasswordDialog();
        }
        forgetPasswordDialog.show(getChildFragmentManager(),"password");
    }

    @OnClick(R.id.btn_setting_my_template)
    public void myTemplate(View view){
        PrescriptionModuleActivity.actionStart(getActivity());
    }
}
